/**
 * 使图形渐显或渐隐
 */ 
package xFGE.util
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class Gradual
	{
		public function Gradual()
		{
		}
		
		static public function gradualShow(dis:DisplayObject):void
		{
			dis.alpha = 0;
//			dis.scaleX = 0.99;
//			dis.scaleY = 0.99;
			dis.visible = true;
			var  timer:Timer = new Timer(20,5)
			timer.addEventListener(TimerEvent.TIMER,tickHandler);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE,completeHandler);
			timer.start();
			
			function tickHandler(event:Event):void
			{
				dis.alpha += 0.2;
//				dis.scaleX += 0.001;
//				dis.scaleY += 0.001;
			}
			function completeHandler(event:Event):void
			{
				dis.alpha = 1;
				dis.scaleX = 1;
				dis.scaleY = 1;
				timer.removeEventListener(TimerEvent.TIMER,tickHandler);
				timer.removeEventListener(TimerEvent.TIMER_COMPLETE,completeHandler);
				timer = null;
			}
		}//end gradualShow
		
		/**
		 * 注意，逐渐消失可以在消失中但没完全消失时向应鼠标事件,请小心使用
		 */ 
		static public function gradualHide(dis:DisplayObject):void
		{
			var  timer:Timer = new Timer(20,5)
			timer.addEventListener(TimerEvent.TIMER,tickHandler);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE,completeHandler);
			timer.start();
			
			function tickHandler(event:Event):void
			{
				dis.alpha -= 0.2;
			}
			function completeHandler(event:Event):void
			{
				dis.visible = false;
				dis.alpha = 1;
				timer.removeEventListener(TimerEvent.TIMER,tickHandler);
				timer.removeEventListener(TimerEvent.TIMER_COMPLETE,completeHandler);
				timer = null;
			}
		}//end gradualShow
		
	}
}